﻿#include<iostream>
using namespace std;
//20241111

class Date {
public://需要注意的时要将构造函数使用public
	Date(int _year, int _month, int _day)//构造，也可以设置缺省参数
	{
		year = _year;
		month = _month;
		day = _day;
	}
	Date()//无参构造
	{
		year = 1990;
		month = 1;
		day = 1;
	}

	int GetMonthDay(int year, int month)//用于获取对应日期
	{
		static int days[13] = { 0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30,
	   31 };

		if (month == 2
			&& ((year % 4 == 0 && year % 100 != 0) || (year % 400 == 0)))
		{
			return 29;
		}
		return days[month];
	}
	bool operator<(const Date& d) const
	{
		if (year < d.year)
		{
			return true;
		}
		else if (year == d.year)
		{
			if (month < d.month)
			{
				return true;
			}
			else if (month == d.month)
			{
				return day < d.day;
			}
		}
		return false;
	}
	/*Date& operator=(Date&date)
	{
		year = date.year;
		month = date.month;
		day = date.day;
		return *this;
	}*/
	bool operator==(const Date& date) const
	{
		return year == date.year \
			&& month == date.month \
			&& day == date.day;
	}
	bool operator<=(const Date& d) const
	{
		return *this < d || *this == d;
	}
	bool operator>(const Date& date) const
	{
		return !(*this <= date);
	}
	bool operator!=(const Date& date) const
	{
		return !(*this == date);
	}

	Date& operator+=(int day)
	{
		if (day < 0)
		{
			return *this -= -day;
		}
		day += day;
		while (day > GetMonthDay(year, month))
		{
			day -= GetMonthDay(year, month);
			++month;
			if (month == 13)
			{
				++year;
				month = 1;
			}
		}
		return *this;
	}
	Date& operator-=(int day)
	{
		if (day < 0)
		{
			return *this += -day;
		}
		day -= day;
		while (day <= 0)
		{
			--month;
			if (month == 0)
			{
				month = 12;
				year--;
			}
			// 借上⼀个⽉的天数
			day += GetMonthDay(year, month);
		}
		return *this;
	}

	Date operator-(int day)
	{
		Date tmp = *this;
		tmp -= day;
		return tmp;
	}
	//++d1
	Date& operator++()
	{
		*this += 1;
		return *this;
	}
	// d1++
	Date operator++(int)
	{
		Date tmp(*this);
		*this += 1;
		return tmp;
	}
	Date& operator--()
	{
		*this -= 1;
		return *this;
	}
	int operator-(const Date& date)
	{
		Date max = *this;
		Date min = date;
		int flag = 1;
		if (*this < date)
		{
			max = date;
			min = *this;
			flag = -1;
		}
		int n = 0;
		while (min != max)
		{
			++min;
			++n;
		}
		return n * flag;
	}

	//private:
	int year;
	int month;
	int day;
};
ostream& operator<<(ostream& out, const Date& date)
{
	out << date.year << ' ' << date.month << ' ' << date.day << endl;
	return out;

}
istream& operator>>(istream& in, Date& date) {
	int year, month, day;
	in >> year >> month >> day;
	Date a;
	if (a.GetMonthDay(year, month) < day || day <= 0)
	{
		cout << "输入日期错误" << endl;
	}
	else
	{
		date.year = year;
		date.month = month;
		date.day = day;
	}
	return in;
}
int main()
{
	Date a;
	Date b = a;

	return 0;
}